//
//  BZBaseViewController.m
//  BiZhi
//
//  Created by ryou on 2021/4/9.
//

#import "BZBaseViewController.h"

@interface BZBaseViewController ()<BUNativeExpressFullscreenVideoAdDelegate,BUNativeExpressBannerViewDelegate>
@property(nonatomic,strong)BUNativeExpressFullscreenVideoAd *BiZhifullscreenAd;
@property(nonatomic, strong) BUNativeExpressBannerView *bannerView;

@end

@implementation BZBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor= kBZMianColor;

    [self loaduadjili];
    // Do any additional setup after loading the view.
}
-(UIActivityIndicatorView *)BZactivity{
    if (!_BZactivity) {
        _BZactivity=[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, kBZScreenW, kBZScreenH)];
        [self.view addSubview:_BZactivity];
    }
    return _BZactivity;
}

-(void)showInterstitialAd{
    
    self.BiZhifullscreenAd = [[BUNativeExpressFullscreenVideoAd alloc] initWithSlotID:kbuadchaping];
    self.BiZhifullscreenAd.delegate = self;
    [self.BiZhifullscreenAd loadAdData];
 

}


- (void)nativeExpressFullscreenVideoAdDidDownLoadVideo:(BUNativeExpressFullscreenVideoAd *)fullscreenVideoAd{
    if (self.BiZhifullscreenAd) {
        [self.BiZhifullscreenAd showAdFromRootViewController:self];
    }
}


-(void)loaduadjili{
    BURewardedVideoModel *model = [[BURewardedVideoModel alloc] init];
    self.burewarAd = [[BUNativeExpressRewardedVideoAd alloc] initWithSlotID:kbuadjili rewardedVideoModel:model];
    [self.burewarAd loadAdData];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/



- (void)bzloadBanner {
    [self.bannerView removeFromSuperview];
    
    UIWindow *window = nil;
    if ([[UIApplication sharedApplication].delegate respondsToSelector:@selector(window)]) {
        window = [[UIApplication sharedApplication].delegate window];
    }
    if (![window isKindOfClass:[UIView class]]) {
        window = [UIApplication sharedApplication].keyWindow;
    }
    if (!window) {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    }
    CGFloat bottom = 0.0;
    if (@available(iOS 11.0, *)) {
        bottom = window.safeAreaInsets.bottom;
    } else {
        // Fallback on earlier versions
    }
    
    CGFloat tabBarHeight = self.navigaviewcontrollertionController.tabBarController.tabBar.frame.size.height;
    bottom =  tabBarHeight;
     CGSize size = CGSizeMake(600, 90);
    NSString * realSlotId = krealSlotId;
    // important: 升级的用户请注意，初始化方法去掉了imgSize参数

    self.bannerView = [[BUNativeExpressBannerView alloc] initWithSlotID:realSlotId rootViewController:self adSize:size interval:10];
        self.bannerView.layer.masksToBounds = YES;

    self.bannerView.frame = CGRectMake(0, self.view.frame.size.height-size.height-bottom, size.width, size.height);
    
    // 不支持中途更改代理，中途更改代理会导致接收不到广告相关回调，如若存在中途更改代理场景，需自行处理相关逻辑，确保广告相关回调正常执行。
    self.bannerView.delegate = self;
    [self.bannerView loadAdData];

}

- (void)showBanner {
    [self.view addSubview:self.bannerView];

}

#pragma BUNativeExpressBannerViewDelegate
- (void)nativeExpressBannerAdViewDidLoad:(BUNativeExpressBannerView *)bannerAdView {
    [self pbud_logWithSEL:_cmd msg:@""];
    [self showBanner];
}


- (void)nativeExpressBannerAdViewDidRemoved:(BUNativeExpressBannerView *)bannerAdView {

    [UIView animateWithDuration:0.25 animations:^{
        bannerAdView.alpha = 0;
    } completion:^(BOOL finished) {
        [bannerAdView removeFromSuperview];
        self.bannerView = nil;
    }];
}

- (void)pbud_logWithSEL:(SEL)sel msg:(NSString *)msg {
}

@end
